/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package archive.resources;


import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import jfilechooserdemo.resources.Decryptor;
import jfilechooserdemo.resources.Encryptor;

class MyCustomFilter extends javax.swing.filechooser.FileFilter {
        @Override
        public boolean accept(File file) {
            return file.isDirectory() || file.exists();
        }
        @Override
        public String getDescription() {
            // This description will be displayed in the dialog,
            // hard-coded = ugly, should be done via I18N
            return "All files";
        }        
    } 

public class Archive extends javax.swing.JFrame {

        /**
         * Creates new form Archive
         */ 
       	public static void getAllFiles(File dir, List<File> fileList) {
		try {
			File[] files = dir.listFiles();
			for (File file : files) {
				fileList.add(file);
				if (file.isDirectory()) {
					System.out.println("directory:" + file.getCanonicalPath());
					getAllFiles(file, fileList);
				} else {
					System.out.println("     file:" + file.getCanonicalPath());
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void writeZipFile(File directoryToZip, List<File> fileList) {

		try {
			FileOutputStream fos = new FileOutputStream(directoryToZip.getCanonicalFile() + ".zip");
			ZipOutputStream zos = new ZipOutputStream(fos);

			for (File file : fileList) {
				if (!file.isDirectory()) { // we only zip files, not directories
					addToZip(directoryToZip, file, zos);
				}
			}

			zos.close();
			fos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void addToZip(File directoryToZip, File file, ZipOutputStream zos) throws FileNotFoundException,
			IOException {

		FileInputStream fis = new FileInputStream(file);

		// we want the zipEntry's path to be a relative path that is relative
		// to the directory being zipped, so chop off the rest of the path
		String zipFilePath = file.getCanonicalPath().substring(directoryToZip.getCanonicalPath().length() + 1,
				file.getCanonicalPath().length());
		System.out.println("Writing '" + zipFilePath + "' to zip file");
		ZipEntry zipEntry = new ZipEntry(zipFilePath);
		zos.putNextEntry(zipEntry);

		byte[] bytes = new byte[1024];
		int length;
		while ((length = fis.read(bytes)) >= 0) {
			zos.write(bytes, 0, length);
		}

		zos.closeEntry();
		fis.close();
	}
         
/** RAR SECTION **/
        
        public static void getAllFilesRar(File dirRar, List<File> fileListRar) {
		try {
			File[] files = dirRar.listFiles();
			for (File file : files) {
				fileListRar.add(file);
				if (file.isDirectory()) {
					System.out.println("directory:" + file.getCanonicalPath());
					getAllFilesRar(file, fileListRar);
				} else {
					System.out.println("     file:" + file.getCanonicalPath());
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void writeZipFileRar(File directoryToRar, List<File> fileListRar) {

		try {
			FileOutputStream fos = new FileOutputStream(directoryToRar.getCanonicalFile() + ".rar");
			ZipOutputStream zos = new ZipOutputStream(fos);

			for (File file : fileListRar) {
				if (!file.isDirectory()) { // we only zip files, not directories
					addToRar(directoryToRar, file, zos);
				}
			}

			zos.close();
			fos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void addToRar(File directoryToRar, File file, ZipOutputStream zos) throws FileNotFoundException,
			IOException {

		FileInputStream fis = new FileInputStream(file);

		// we want the zipEntry's path to be a relative path that is relative
		// to the directory being zipped, so chop off the rest of the path
		String rarFilePath = file.getCanonicalPath().substring(directoryToRar.getCanonicalPath().length() + 1,
				file.getCanonicalPath().length());
		System.out.println("Writing '" + rarFilePath + "' to rar file");
		ZipEntry rarEntry = new ZipEntry(rarFilePath);
		zos.putNextEntry(rarEntry);

		byte[] bytes = new byte[1024];
		int length;
		while ((length = fis.read(bytes)) >= 0) {
			zos.write(bytes, 0, length);
		}

		zos.closeEntry();
		fis.close();
	}
        
  /** ------------------------------------------------ */      
        
        
        /** gzip SECTION **/
        
        public static void getAllFilesGzip(File dirGzip, List<File> fileListGzip) {
		try {
			File[] files = dirGzip.listFiles();
			for (File file : files) {
				fileListGzip.add(file);
				if (file.isDirectory()) {
					System.out.println("directory:" + file.getCanonicalPath());
					getAllFilesGzip(file, fileListGzip);
				} else {
					System.out.println("     file:" + file.getCanonicalPath());
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void writeZipFileGzip(File directoryToGzip, List<File> fileListGzip) {

		try {
			FileOutputStream fos = new FileOutputStream(directoryToGzip.getCanonicalFile() + ".gzip");
			ZipOutputStream zos = new ZipOutputStream(fos);

			for (File file : fileListGzip) {
				if (!file.isDirectory()) { // we only zip files, not directories
					addToRar(directoryToGzip, file, zos);
				}
			}

			zos.close();
			fos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void addToGzip(File directoryToGzip, File file, ZipOutputStream zos) throws FileNotFoundException,
			IOException {

		FileInputStream fis = new FileInputStream(file);

		// we want the zipEntry's path to be a relative path that is relative
		// to the directory being zipped, so chop off the rest of the path
		String GzipFilePath = file.getCanonicalPath().substring(directoryToGzip.getCanonicalPath().length() + 1,
				file.getCanonicalPath().length());
		System.out.println("Writing '" + GzipFilePath + "' to rar file");
		ZipEntry GzipEntry = new ZipEntry(GzipFilePath);
		zos.putNextEntry(GzipEntry);

		byte[] bytes = new byte[1024];
		int length;
		while ((length = fis.read(bytes)) >= 0) {
			zos.write(bytes, 0, length);
		}

		zos.closeEntry();
		fis.close();
	}
        
  /** ------------------------------------------------ */ 

        
           /** JAR SECTION **/
        
        public static void getAllFilesJar(File dirJar, List<File> fileListJar) {
		try {
			File[] files = dirJar.listFiles();
			for (File file : files) {
				fileListJar.add(file);
				if (file.isDirectory()) {
					System.out.println("directory:" + file.getCanonicalPath());
					getAllFilesJar(file, fileListJar);
				} else {
					System.out.println("     file:" + file.getCanonicalPath());
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void writeZipFileJar(File directoryToJar, List<File> fileListJar) {

		try {
			FileOutputStream fos = new FileOutputStream(directoryToJar.getCanonicalFile() + ".jar");
			ZipOutputStream zos = new ZipOutputStream(fos);

			for (File file : fileListJar) {
				if (!file.isDirectory()) { // we only zip files, not directories
					addToRar(directoryToJar, file, zos);
				}
			}

			zos.close();
			fos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void addToJar(File directoryToJar, File file, ZipOutputStream zos) throws FileNotFoundException,
			IOException {

		FileInputStream fis = new FileInputStream(file);

		// we want the zipEntry's path to be a relative path that is relative
		// to the directory being zipped, so chop off the rest of the path
		String JarFilePath = file.getCanonicalPath().substring(directoryToJar.getCanonicalPath().length() + 1,
				file.getCanonicalPath().length());
		System.out.println("Writing '" + JarFilePath + "' to rar file");
		ZipEntry JarEntry = new ZipEntry(JarFilePath);
		zos.putNextEntry(JarEntry);

		byte[] bytes = new byte[1024];
		int length;
		while ((length = fis.read(bytes)) >= 0) {
			zos.write(bytes, 0, length);
		}

		zos.closeEntry();
		fis.close();
	}
        
  /** ------------------------------------------------ */ 
         
        public Archive() {
                initComponents();
        }

        /**
         * This method is called from within the constructor to initialize the form. WARNING: Do NOT
         * modify this code. The content of this method is always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
  
        
        
        
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fileChooser = new javax.swing.JFileChooser();
        archiveOptions = new javax.swing.ButtonGroup();
        archiveButton = new javax.swing.JButton();
        source = new javax.swing.JTextField();
        choosefolder = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        zip = new javax.swing.JRadioButton();
        rar = new javax.swing.JRadioButton();
        gzip = new javax.swing.JRadioButton();
        jar = new javax.swing.JRadioButton();
        Encrypt = new javax.swing.JButton();
        decrypt = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        decompress = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        choosefile = new javax.swing.JButton();
        source1 = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JSeparator();
        status = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        pathToEnc = new javax.swing.JTextField();
        jSeparator5 = new javax.swing.JSeparator();
        status1 = new javax.swing.JLabel();
        status2 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        status4 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        filemenu = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        fileChooser.setDialogTitle("This is my open dialog");
        fileChooser.setFileFilter(new MyCustomFilter());

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Demo application");
        setBackground(new java.awt.Color(153, 255, 255));
        setMinimumSize(new java.awt.Dimension(456, 550));
        setPreferredSize(new java.awt.Dimension(456, 550));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        archiveButton.setText("Compress");
        archiveOptions.add(archiveButton);
        archiveButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                archiveButtonMouseClicked(evt);
            }
        });
        archiveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                archiveButtonActionPerformed(evt);
            }
        });
        getContentPane().add(archiveButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 280, 100, 30));
        getContentPane().add(source, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 380, 290, 30));

        choosefolder.setText("Choose file");
        choosefolder.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                choosefolderMouseClicked(evt);
            }
        });
        choosefolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                choosefolderActionPerformed(evt);
            }
        });
        getContentPane().add(choosefolder, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 240, 100, 30));

        
        getContentPane().add(choosefile, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 373, 100, 30));
        getContentPane().add(source1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 250, 290, 30));
        getContentPane().add(jSeparator2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 340, 460, -1));

        jLabel5.setText("Choose Folder to Compress:");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 210, -1, 31));
        getContentPane().add(jSeparator4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 110, 460, 10));
        getContentPane().add(status, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 110, 190, 30));

        jButton1.setText("Choose file");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 140, 100, 30));
        getContentPane().add(pathToEnc, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 140, 290, 30));
        getContentPane().add(jSeparator5, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 210, 460, -1));
        getContentPane().add(status1, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 210, 180, 30));
        getContentPane().add(status2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 450, 430, 30));

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/archive/resources/logo.png"))); // NOI18N
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 490, 110));
        getContentPane().add(status4, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 340, 180, 30));


        filemenu.setText("File");

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        jMenuItem2.setText("Exit");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        filemenu.add(jMenuItem2);

        jMenuBar1.add(filemenu);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void archiveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_archiveButtonActionPerformed
   
    }//GEN-LAST:event_archiveButtonActionPerformed

    private void archiveButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_archiveButtonMouseClicked
        String ftype = "";
                  if (zip.isSelected())
                        ifZip();
                  else if (rar.isSelected())
                        ifRar();
                  else if (gzip.isSelected())
                        ifGzip();
                  else if (jar.isSelected())
                        ifJar();
  
    }//GEN-LAST:event_archiveButtonMouseClicked

    private void choosefolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_choosefolderActionPerformed
  JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle("Open Folder");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        source1.setText(chooser.getSelectedFile().toString());
      System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
      System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
    } else {
      System.out.println("No Selection ");
    }
//        	File directoryToZip = new File("C:\\Users\\Admin\\Desktop\\sa");
//
//		List<File> fileList = new ArrayList<File>();
//		System.out.println("---Getting references to all files in: ");
//		System.out.println("---Creating zip file");
//		writeZipFile(directoryToZip, fileList);
//		System.out.println("---Done");
//    
    
    
    
    }//GEN-LAST:event_choosefolderActionPerformed

    

    private void choosefileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_choosefileActionPerformed
         int result;
            
            fileChooser.setCurrentDirectory(new java.io.File("."));
            fileChooser.setDialogTitle("Open File");
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
   
            fileChooser.setAcceptAllFileFilterUsed(false);
        
            if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                source.setText(fileChooser.getSelectedFile().toString());
                  System.out.println("getCurrentDirectory(): "
                    +  fileChooser.getCurrentDirectory());
                  System.out.println("getSelectedFile() : "
                    +  fileChooser.getSelectedFile());
             }
            else {
             System.out.println("No Selection ");
             } 
            
    }//GEN-LAST:event_choosefileActionPerformed

    private void decompressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_decompressActionPerformed
       try {
			ZipFile zipFile = new ZipFile(fileChooser.getSelectedFile());
			Enumeration<?> enu = zipFile.entries();
			while (enu.hasMoreElements()) {
				ZipEntry zipEntry = (ZipEntry) enu.nextElement();

				String name = fileChooser.getCurrentDirectory()+ "\\"+ zipEntry.getName();
				long size = zipEntry.getSize();
				long compressedSize = zipEntry.getCompressedSize();
				System.out.printf("name: %-20s | size: %6d | compressed size: %6d\n", 
						name, size, compressedSize);

				File file = new File(name);
				if (name.endsWith("/")) {
					file.mkdirs();
					continue;
				}

				File parent = file.getParentFile();
				if (parent != null) {
					parent.mkdirs();
				}

				InputStream is = zipFile.getInputStream(zipEntry);
				FileOutputStream fos = new FileOutputStream(file);
				byte[] bytes = new byte[1024];
				int length;
				while ((length = is.read(bytes)) >= 0) {
					fos.write(bytes, 0, length);
				}
                               status4.setText("Done decompressing!");
                               status2.setText(parent.toString());
                               
				is.close();
				fos.close();

			}
			zipFile.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	
    }//GEN-LAST:event_decompressActionPerformed

    private void choosefileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_choosefileMouseClicked
  
    }//GEN-LAST:event_choosefileMouseClicked

    private void choosefolderMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_choosefolderMouseClicked
 
    }//GEN-LAST:event_choosefolderMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        int returnVal = fileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        pathToEnc.setText(file.getAbsolutePath());
    } else {
        System.out.println("File access cancelled by user.");
    
    }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
                /* Set the Nimbus look and feel */
                //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
                 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
                 */
                try {
                        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                                if ("Nimbus".equals(info.getName())) {
                                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                                        break;
                                }
                        }
                } catch (ClassNotFoundException ex) {
                        java.util.logging.Logger.getLogger(Archive.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                        java.util.logging.Logger.getLogger(Archive.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                        java.util.logging.Logger.getLogger(Archive.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                        java.util.logging.Logger.getLogger(Archive.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                }
                //</editor-fold>

                /* Create and display the form */
                java.awt.EventQueue.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            new Archive().setVisible(true);
                                
                              
                        }
                });
        }
        
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Encrypt;
    private javax.swing.JButton archiveButton;
    private javax.swing.ButtonGroup archiveOptions;
    private javax.swing.JButton choosefile;
    private javax.swing.JButton choosefolder;
    private javax.swing.JButton decompress;
    private javax.swing.JButton decrypt;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JMenu filemenu;
    private javax.swing.JRadioButton gzip;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JRadioButton jar;
    private javax.swing.JTextField pathToEnc;
    private javax.swing.JRadioButton rar;
    private javax.swing.JTextField source;
    private javax.swing.JTextField source1;
    private javax.swing.JLabel status;
    private javax.swing.JLabel status1;
    private javax.swing.JLabel status2;
    private javax.swing.JLabel status4;
    private javax.swing.JRadioButton zip;
    // End of variables declaration//GEN-END:variables

    private void getCurrentDirectoy() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
    private void ifZip() {
       String x =source1.getText();
        File directoryToZip = new File(x);

		List<File> fileList = new ArrayList<File>();
		System.out.println("---Getting references to all files in: ");
		getAllFiles(directoryToZip, fileList);
		System.out.println("---Creating zip file");
		writeZipFile(directoryToZip, fileList);
		//System.out.println("---Done");
                status1.setText("Archive Done-Zip!");
           }

    private void ifRar() {
        String x =source1.getText();
        File directoryToRar = new File(x);
        
        List<File> fileListRar = new ArrayList<File>();
		System.out.println("---Getting references to all files in: ");
		getAllFilesRar(directoryToRar, fileListRar);
		System.out.println("---Creating zip file");
		writeZipFileRar(directoryToRar, fileListRar);
		//System.out.println("---Done");
                status1.setText("Archive Done-Rar!");
            }

    private void ifGzip() {
        String x =source1.getText();
        File directoryToGzip = new File(x);
        
        List<File> fileListGzip = new ArrayList<File>();
		System.out.println("---Getting references to all files in: ");
		getAllFilesGzip(directoryToGzip, fileListGzip);
		System.out.println("---Creating zip file");
		writeZipFileGzip(directoryToGzip, fileListGzip);
		//System.out.println("---Done");
                status1.setText("Archive Done-Gzip!");
    }

    private void ifJar() {
         String x =source1.getText();
        File directoryToJar = new File(x);
        
        List<File> fileListJar = new ArrayList<File>();
		System.out.println("---Getting references to all files in: ");
		getAllFilesJar(directoryToJar, fileListJar);
		System.out.println("---Creating zip file");
		writeZipFileJar(directoryToJar, fileListJar);
		//System.out.println("---Done");
                status1.setText("Archive Done-Jar!");
      
            }
}